﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TomVanGaever.BCS.Parser
{
    public partial class BCSParserEntityServicePickerControl : BCSUserControl
    {

        public IEnumerable<Type> DataSource { get; set; }
        public string TypeMember { get; set; }

        public Type SelectedType
        {
            get { return lstServiceClasses.SelectedItem as Type; }
        }

		public override string TitleText
		{
			get
			{
				label2.Visible = false;
				return label2.Text;
			}
		} 
        
        public void DataBind() {
            IEnumerable<Type> entities = this.DataSource.Where(t => t.GetProperties().Count() != 0).ToList();
            lstServiceClasses.DisplayMember = this.TypeMember;
            lstServiceClasses.DataSource = DataSource;    
        }

        public override string GetStatusString()
        {
            string result = "Selected service:\t\t\t\t\t {0}";
            return string.Format(result, this.SelectedType.FullName);
        }

        public BCSParserEntityServicePickerControl()
        {
            InitializeComponent();
        }

        private void chFilter_CheckedChanged(object sender, EventArgs e)
        {
            if (chFilter.Checked)
            {
                lstServiceClasses.DataSource = DataSource.Where(t => t.Name.ToLower().Contains("service")).ToList();
            }
            else
            {
                lstServiceClasses.DataSource = DataSource.ToList();
            }
        }

    }
}
